package com.huarui.companyconfig.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.springframework.orm.ibatis.SqlMapClientCallback;

import com.huarui.companyconfig.dao.ICompanyConfigDao;
import com.huarui.companyconfig.model.CompanyConfig;
import com.huarui.initialItem.model.InitialItem;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class CompanyConfigDaoImpl extends BaseDaoImpl implements ICompanyConfigDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<CompanyConfig> getListByConditions(Map map) {
		
		return this.getSqlMapClientTemplate().queryForList(namespace+".getListByCondition", map);
	}

	@Override
	public void batchInsert(final List<CompanyConfig> list) {
		this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {    
                executor.startBatch();
                for (CompanyConfig item:list) {    
                    executor.insert(namespace+".create",item);               	
                }            
                executor.executeBatch();           
                return null;
            }
		});
	}

	@Override
	public void batchUpdate(final List<CompanyConfig> list) {
		this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {    
                executor.startBatch();
                for (CompanyConfig item:list) {    
                    executor.insert(namespace+".update",item);               	
                }            
                executor.executeBatch();           
                return null;
            }
		});
	}

}
